<template>
  <div>
    <el-avatar :size="80" src="https://empty" @error="errorHandler">
      <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png" />
    </el-avatar>
    <el-button type="text" @click="handeGo">进入后台系统</el-button>
  </div>
</template>
<script>
import { getUserInfo, loginAdmin } from "@/api/user";

export default {
  name: "UserInfo",
  props: {},
  created() {
    getUserInfo()
      .then(response => {
        this.temp = response.data;
      })
      .catch(error => {
        console.error(error);
      });
  },
  methods: {
    errorHandler() {
      return true;
    },
    handeGo() {
      const loading = this.$loading({
        text: "正在访问后台管理系统，请等候..."
      });
      loginAdmin()
        .then(response => {
          loading.close();
          if (response.success) {
            window.open(response.message);
          } else {
            this.$notify({
              title: "访问失败",
              message: response.message,
              type: "error",
              duration: 2000
            });
          }
        })
        .catch(error => {
          loading.close();
          console.info(error);
        });
    }
  }
};
</script>